package com.laf.mall.api.repository;

import com.laf.mall.api.dto.MemberCar;
import com.laf.mall.api.dto.MemberSetting;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author ygl
 * @create 2018-12-26
 * @DESCRIPTION
 **/
@Repository
@Slf4j
public class MemberSettingRepository {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 通过 会员ID 查询 会员设置
     * @param memberId
     * @return
     */
    public List<MemberSetting> findByMemberId(Integer memberId){
        String sql = "SELECT * FROM t_member_setting WHERE member_id = ?";
        List<MemberSetting> list = jdbcTemplate.query(sql,new Object[]{memberId},new MemberSetting());
        return list;
    }

    /**
     * 通过 会员ID 和 设置 新增
     * @param memberId
     * @param autoOffsetParkingRate
     * @return
     */
    public int insert(Integer memberId,Integer autoOffsetParkingRate){
        String sql = "INSERT INTO t_member_setting(member_id,auto_offset_parking_rate) VALUES (?,?)";
        return jdbcTemplate.update(sql,new Object[]{memberId,autoOffsetParkingRate});
    }

    public int update(Integer memberId, Integer autoOffsetParkingRate) {
        String sql = "update t_member_setting set auto_offset_parking_rate=? where member_id=?";
        return jdbcTemplate.update(sql, new Object[]{autoOffsetParkingRate,memberId});
    }
}
